package com.waimai1.waimai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.waimai1.waimai.dao.LocalShopDao;
import com.waimai1.waimai.entity.LocalGood;
import com.waimai1.waimai.entity.LocalShop;
import com.waimai1.waimai.service.LocalShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * (LocalShop)表服务实现类
 *
 * @author makejava
 * @since 2023-11-14 20:45:20
 */
@Service("localShopService")
public class LocalShopServiceImpl extends ServiceImpl<LocalShopDao, LocalShop> implements LocalShopService {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public LocalShop addSoldCount(LocalShop shop){
        Object osoldcount=redisTemplate.opsForHash().get("LSsoldCount","shopId"+shop.getId());
        Integer soldcount;
        if(null==osoldcount){
            soldcount=(int)(Math.random() * 1000);
            redisTemplate.opsForHash().put("LSsoldCount","shopId"+shop.getId(),String.valueOf(soldcount));
        }else{
            soldcount=Integer.valueOf((String)osoldcount);
        }
        shop.setSoldCount(null!=soldcount?soldcount:(int)(Math.random() * 1000));
        return shop;
    }
}

